package com.penton.util.widget.treelistview;

import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

import com.penton.util.R;
import com.penton.util.widget.treelistview.TreeView.LastLevelItemClickListener;

public class TreeViewActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tree_view_layout);
		TreeView treeView = (TreeView) findViewById(R.id.tree_view);
		/**
		 * 锟解部锟街可革拷锟绞碉拷锟斤拷锟揭拷锟斤拷锟斤拷谓诘锟斤拷锟较拷锟饺★拷锟绞斤拷锟斤拷锟斤拷取锟截讹拷锟斤拷式锟斤拷json锟街凤拷
		 */
		List<String> treeElementsString = ResManager.loadTextRes(
				"treeview_elements", this);// 锟斤拷锟斤拷锟斤拷诠锟斤拷锟絘ssets/textRes目录锟铰碉拷锟侥硷拷锟斤拷源
		/**
		 * 锟斤拷锟斤拷也锟斤拷锟斤拷直锟斤拷new锟斤拷锟杰讹拷TreeElement实锟斤拷然锟斤拷玫锟斤拷锟斤拷谓诘锟侥硷拷锟较ｏ拷锟斤拷锟斤拷锟节碉拷芏锟侥伙拷锟杰诧拷锟斤拷锟斤拷
		 */
		List<TreeElement> treeElements = TreeElementParser
				.getTreeElements(treeElementsString);// 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟侥硷拷锟斤拷源锟斤拷锟斤拷

		LastLevelItemClickListener itemClickCallBack = new LastLevelItemClickListener() {// 锟斤拷锟斤拷锟节碉拷锟斤拷锟铰硷拷锟斤拷锟斤拷
			@Override
			public void onLastLevelItemClick(int position,
					TreeViewAdapter adapter) {
				TreeElement element = (TreeElement) adapter.getItem(position);
				Toast.makeText(getApplicationContext(), element.getTitle(), 300)
						.show();
			}
		};
		treeView.initData(this, treeElements);// 锟斤拷始锟斤拷锟斤拷锟�		treeView.setLastLevelItemClickCallBack(itemClickCallBack);// 锟斤拷锟矫节碉拷锟斤拷锟铰硷拷锟斤拷锟斤拷
	}
}